package view;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.border.LineBorder;

import java.awt.Color;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JRadioButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.ParseException;

import javax.swing.table.DefaultTableModel;

public class JCliente extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private JTable tabela;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			JCliente dialog = new JCliente(null, true);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public JCliente(JFrame pai, boolean modal) {
		super(pai, modal);
		setResizable(false);
		setModalityType(ModalityType.APPLICATION_MODAL);
		setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
		setLocationRelativeTo(null);
		setModal(true);
		setTitle("Gerenciar clientes");
		setBounds(100, 100, 1022, 714);
		getContentPane().setLayout(null);
		contentPanel.setBounds(0, 0, 1004, 676);
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel);
		
		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(new Color(128, 128, 128), 1, true));
		
		tabela = new JTable();
		tabela.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"C\u00F3digo", "Nome", "E-mail", "Telefone", "Celular"
			}
		));
		tabela.getColumnModel().getColumn(0).setResizable(false);
		tabela.getColumnModel().getColumn(0).setPreferredWidth(45);
		tabela.getColumnModel().getColumn(1).setPreferredWidth(275);
		tabela.getColumnModel().getColumn(2).setPreferredWidth(275);
		tabela.getColumnModel().getColumn(3).setPreferredWidth(105);
		tabela.getColumnModel().getColumn(4).setPreferredWidth(105);
		
		
		
		JLabel lblBusca = new JLabel("Busca:");
		
		textField = new JTextField();
		textField.setColumns(10);
		
		JLabel lblTipo = new JLabel("Tipo:");
		
		JRadioButton txtCodigo = new JRadioButton("Código");
		
		JRadioButton txtNome = new JRadioButton("Nome");
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addComponent(lblBusca)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(textField, GroupLayout.PREFERRED_SIZE, 410, GroupLayout.PREFERRED_SIZE)
							.addGap(34)
							.addComponent(lblTipo)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtCodigo)
							.addGap(18)
							.addComponent(txtNome))
						.addComponent(tabela, GroupLayout.PREFERRED_SIZE, 786, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addComponent(panel, GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(panel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblTipo)
								.addComponent(txtCodigo)
								.addComponent(txtNome)
								.addComponent(lblBusca)
								.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(18)
							.addComponent(tabela, GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)))
					.addContainerGap())
		);
		
		JButton btnAdicionar = new JButton("Adicionar");
		btnAdicionar.setBounds(30, 27, 117, 63);
		btnAdicionar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				exibirJanelaCadastroCliente();
				
			}
		});
		
		JButton btnAlterar = new JButton("Alterar");
		btnAlterar.setBounds(30, 131, 117, 63);
		
		JButton btnPesquisar = new JButton("Pesquisar");
		btnPesquisar.setBounds(30, 340, 117, 63);
		
		JButton btnExcluir = new JButton("Excluir");
		btnExcluir.setBounds(30, 234, 117, 63);
		
		JButton btnFechar = new JButton("Fechar");
		btnFechar.setBounds(30, 553, 117, 57);
		panel.setLayout(null);
		panel.add(btnPesquisar);
		panel.add(btnExcluir);
		panel.add(btnFechar);
		panel.add(btnAdicionar);
		panel.add(btnAlterar);
		
		JButton btnRelatrios = new JButton("Relatórios");
		btnRelatrios.setBounds(30, 446, 117, 63);
		panel.add(btnRelatrios);
		contentPanel.setLayout(gl_contentPanel);
		
		ButtonGroup pesquisa = new ButtonGroup();
		pesquisa.add(txtCodigo);
		pesquisa.add(txtNome);
	}
	
	
	private void exibirJanelaCadastroCliente(){
		JClienteAdicionar jclienteAdicionar;
		try {
			jclienteAdicionar = new JClienteAdicionar(this, true);
			jclienteAdicionar.setLocationRelativeTo(null);
			//jclienteAdicionar.setModal(true);
			jclienteAdicionar.setVisible(true);
			jclienteAdicionar.setResizable(false);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
}

